///Object类的拓展方法
extension ObjectExt on Object {
  ///动态类型到基本类型的转换，支持null-safety。
  double toDouble() {
    if (this is double) {
      return this as double;
    }
    return 0.0;
  }

  ///转为 Bool
  bool toBool() {
    if (this is bool) {
      return this as bool;
    }
    return false;
  }

  ///转为Int
  int toInt() {
    if (this is int) {
      return this as int;
    }
    return 0;
  }

  ///判断是否为String类型，是则转为String 并返回
  // String asString() {
  //   if (this is String) {
  //     return this as String;
  //   }
  //   return '';
  // }

  ///转为List
  List<T> toList<T>() {
    if (this is List<Object>) {
      return (this as List<Object>).map((Object e) => e as T).toList();
    }

    return <T>[];
  }

  ///转为指定的Map类型
  Map<K, V> toMap<K, V>() {
    if (this is Map<K, V>) {
      return this as Map<K, V>;
    }
    return <K, V>{};
  }

  ///转为[T]指定的类型
  T? to<T>() {
    if (this is T) {
      return this as T;
    }
    return null;
  }
}
